$(function () {
    let productId = sessionStorage.getItem("productId");
    // console.log(productId, "-----qqq")
    findById(productId);
})

layui.use(['form', 'layer', 'jquery', 'laydate'],
    function () {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer
            , laydate = layui.laydate;
        //日期
        laydate.render({
            elem: '#birthday',
            trigger: 'click'
        });
        //表单取值
        layui.$('#LAY-component-form-getval').on('click', function () {
            var data = form.val('example');
            alert(JSON.stringify(data));
            console.log(data, "111111")
        });
        //监听提交
        form.on('submit(edit)',
            function (data) {
                data = data.field;
                console.log(data,"2222222");


            });

    });

function findById(productId) {
    $.ajax({
        url: '/back/product/findById',
        data: {productId: productId},
        dataType: "json",
        type: 'get',
        success: function (data) {
            // console.log(data, "kankan");
            setUserData(data.data);
        }
    })
}

//赋值
function setUserData(data) {
    // console.log(data,"赋值");
    layui.use(['form'],
        function () {
            let form = layui.form;
            $("#id").val(data.id);
            $('select > option').each(function () {
                if (data.typeName == $(this).val()) {
                    $(this).attr("selected", true);
                }
            });
            $("#name").val(data.name);
            $("#normalPrice").val(data.normalPrice);
            $("input[name='isShow'][value='" + data.isShow + "']").attr("checked", true);
            $("input[name='isRecommend'][value='" + data.isRecommend + "']").attr("checked", true);
            $("#content").html(data.content);
            form.render();//重新渲染
        });

}